﻿/****** Object:  UserDefinedFunction [dbo].[StringSplit]    Script Date: 09/05/2012 17:18:36 ******/
CREATE function [dbo].[StringSplit] (@String varchar(max), @Delimiter char(1))
Returns @Results Table (ITEM varchar(1000) collate SQL_Latin1_General_CP1_CI_AS)
As

Begin
Declare @Index int
Declare @Slice nvarchar(4000)
Select @Index = 1
If @String Is NULL Return

While @Index != 0
Begin

Select @Index = (CharIndex(@Delimiter, @String))
If (@Index != 0)
Select @Slice = left(@String, @Index - 1)
else
Select @Slice = @String
Insert into @Results(ITEM) Values (@Slice)
Select @String = right(@String, Len(@String) - @Index)
If Len(@String) = 0 break
End
Return
End

GO
